package com.ming.springboot.controller;

import com.ming.springboot.util.PropertiesHelper;
import com.ming.springboot.vo.Student;
import com.ming.springboot.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by mqsi on 2022/5/8 12:18
 */
@RestController
@RequestMapping("properties")
public class PropertiesController {
	@Value("${server.port}")
	private String port;
	@Value("${spring.boot.msg}")
	private String msg;
	@Autowired
	protected User user;
	@Autowired
	private Student student;

	@RequestMapping("/hello.action")
	public Object hello() {
		String view = "Server port:" + port + ", msg:" + msg;
		return view;
	}

	@RequestMapping(value = "/user.action", produces = "application/json; charset=gbk")
	public Object userInfo() {
		return user.toString();
	}

	@RequestMapping(value = "/student.action")
	public Object student() {
		return student.toString();
	}

	@RequestMapping("/properties.action")
	public Object getProperties() {
		String msg = null;
		String serverPort = PropertiesHelper.getProperties("server.port");
		String userId = PropertiesHelper.getProperties("spring.boot.user.userId");
		String sno = PropertiesHelper.getProperties("spring.boot.student.sno");
		msg = "服务端口：" + serverPort + "," +
				"用户编号：" + userId + "," +
				"学生编号：" + sno;
		return msg;
	}
}
